/*
 * Simulation.cpp
 *
 *  Created on: Apr 9, 2012
 *      Author: lfelipe
 */
#include <sys/types.h>
#include <sys/stat.h>

#include "Simulation.h"
#include "../Boundary/Config.h"

Simulation::~Simulation()
{
    delete this->circuit;
    delete this->statistic;
    delete this->tex_name;
}

std::string Simulation::generate_circuit_name_sequence(const std::string &name)
{
    return circuit->generate_name(name);
}


Simulation::Simulation()
{
    Config config = Config::get_instance();
    this->folder = config.get_config_string("SIMULATION_STATICS_PATH")+"SIMULATION_"+FileNameSequence::gerenate_time_string();
    this->circuit = new FileNameSequence(this->folder+"/CIRCUIT_"+FileNameSequence::gerenate_time_string());
    this->statistic = new FileNameSequence(this->folder+"/RESULTS_"+FileNameSequence::gerenate_time_string());
    this->tex_name = new FileNameSequence(this->folder+"/TEX_"+FileNameSequence::gerenate_time_string(),".tex");
}

Simulation::Simulation(const Simulation & simulation)
{
    if(this != &simulation){
        this->folder = simulation.folder;
        this->circuit = new FileNameSequence(simulation.circuit->base_name());
        this->statistic = new FileNameSequence(simulation.statistic->base_name());
        this->tex_name = new FileNameSequence(simulation.tex_name->base_name());
    }
}

Simulation & Simulation::operator =(const Simulation & simulation)
{
    if(this != &simulation){
        delete this->circuit;
        delete this->statistic;
        delete this->tex_name;
        this->folder = simulation.folder;
        this->circuit = new FileNameSequence(simulation.circuit->base_name());
        this->statistic = new FileNameSequence(simulation.statistic->base_name());
        this->tex_name = new FileNameSequence(simulation.tex_name->base_name());
    }
    return *this;
}

std::string Simulation::generate_statistics_name_sequence()
{
    return statistic->generate_name();
}

std::string Simulation::generate_tex_name_sequence(const std::string & name)
{
    return tex_name->generate_name(name);
}

std::string Simulation::generate_folder_name_sequence()
{
    return folder;
}

void Simulation::clear_simulation()
{
    Config config = Config::get_instance();
    this->folder = config.get_config_string("SIMULATION_STATICS_PATH")+"SIMULATION_"+FileNameSequence::gerenate_time_string();
    *this->circuit = FileNameSequence(this->folder+"/CIRCUIT_");
    *this->statistic = FileNameSequence(this->folder+"/RESULTS_");
    *this->tex_name = FileNameSequence(this->folder+"/TEX_",".tex");
}

int Simulation::create_folder()
{
    int status;
    status = mkdir(folder.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    return status;
}








